///*
// *  Copyright (c) 2013.
// *  * 游戏服务器核心代码编写人陈磊拥有使用权
// *  * 联系方式：E-mail:13638363871@163.com ;qq:502959937
// *  * 个人博客主页：http://my.oschina.net/chenleijava
// */
//
//package com.dc.gameserver.serverCore.controller.handleController.itemsController;
//
//import com.dc.gameserver.serverCore.controller.AbstractController.AbstractController;
//import com.dc.gameserver.serverCore.controller.AbstractController.IController;
//import com.dc.gameserver.serverCore.model.dbsql.modelCache.ModelCacheService;
//import com.dc.gameserver.serverCore.model.dbsql.modelService.PlayerService;
//import com.dc.gameserver.serverCore.model.dbsql.modelService.RoleItemService;
//import com.dc.gameserver.serverCore.service.character.PlayerInstance;
//import com.google.protobuf.MessageLite;
//import org.springframework.stereotype.Service;
//
//import javax.annotation.Resource;
//
///**
// * Created by 石头哥哥 on 13-12-16.
// * 购买 装备  秘籍 技能书  道具等
// */
//@Service
//public class buyController extends AbstractController {
//
//    @Resource
//    private PlayerService playerService;
//
//    @Resource
//    private RoleItemService roleItemService;
//
//    @Resource
//    private ModelCacheService modelCacheService;
//
//   @Override
//    public void PostConstruct() {
//       int ID= buyItemRequest.msgID.ID_VALUE;
//       GAME_CONTROLLERS[ID]=this;
//       IController.MESSAGE_LITE[ID]=buyItemRequest.getDefaultInstance();
//    }
//
//    /**
//     required uint32 itemTypeID = 1; //购买物品ID编号 配置文件编号
//     required uint32 itemType=2;//itemType:1 装备 2.秘籍 3.道具
//     购买物品的流通货币
//     * @param messageLite     数据载体
//     * @param player active object
//     * @throws Exception
//     */
//    @Override
//    public void DispatchMessageLit(MessageLite messageLite, PlayerInstance player) throws Exception {
////        buyItemRequest buyItemRequest= (buyItemRequest) messageLite;
////        int itemTypeID=buyItemRequest.getItemTypeID(); //购买物品ID编号 配置文件编号
////        int  itemType=buyItemRequest.getItemType(); //itemType:1 装备 2.秘籍 3.道具
////        int roleID= player.getID();
////        TRole tRole= (TRole) modelCacheService.findByPrefixID(ModelCacheService.ROLE_PREFIX(roleID));
////        //player lingshi num
////        int lingShi=tRole.getRolelingshinum();
////        buyItemResponse.Builder builder=buyItemResponse.newBuilder();
////        int result=0;//1.购买物品成功；2.灵石数量不够；3.其他未知错误
////        //1 装备
////        if (itemType== 0x1){
////           EquipmentModel equipmentModel= ScriptFactory.equipmentModelFastMap.get(itemTypeID);
////           int cast=equipmentModel.getPrice();
////           if(lingShi>=cast){
////               TRoleItem roleItem= (TRoleItem) roleItemService.recordGoods(roleID, itemTypeID, itemType, ItemOptType.BUY_GOODS.getValue());
////               tRole.setRolelingshinum(lingShi-cast);
////               playerService.updateRole(tRole);//请求的时候在推送
////               modelCacheService.addObjectPrefixID(ModelCacheService.ROLE_PREFIX(roleID),tRole);
////               result= 0x1;
////               //构建购买物品数据信息
////               buyItemVO.Builder _buyItem=buyItemVO.newBuilder();
////               _buyItem.setItemID(roleItem.getItemid());  //服务器分配的编号（自增长唯一标识）
////               _buyItem.setItemTypeID(roleItem.getItemtypeid());  //物品ID编号 配置文件编号
////               _buyItem.setItemType(roleItem.getItemtype());//itemType:1 装备 2.秘籍 3.道具
////               builder.addBuyItemList(_buyItem.build());
////               builder.setLingShiNum(tRole.getRolelingshinum());
////           }else {
////               result= 0x2;
////               builder.setResult(result);
////           }
////           player.DirectSend(wrappedBufferShort(buyItemResponse.msgID.ID_VALUE,builder.build()));
////           return;
////        }
////        //2.秘籍
////        if (itemType== 0x2){
////            BookModel bookModel=ScriptFactory.bookModelFastMap.get(itemTypeID);
////            int cast=bookModel.getPrice();
////            if (lingShi>=cast){
////                TRoleItem roleItem= (TRoleItem) roleItemService.recordGoods(roleID, itemTypeID, itemType, ItemOptType.BUY_GOODS.getValue());
////                tRole.setRolelingshinum(lingShi-cast);
////                playerService.updateRole(tRole);
////                modelCacheService.addObjectPrefixID(ModelCacheService.ROLE_PREFIX(roleID), tRole);
////                result= 0x1;
////                //构建购买物品数据信息
////                buyItemVO.Builder _buyItem=buyItemVO.newBuilder();
////                _buyItem.setItemID(roleItem.getItemid());  //服务器分配的编号（自增长唯一标识）
////                _buyItem.setItemTypeID(roleItem.getItemtypeid());  //物品ID编号 配置文件编号
////                _buyItem.setItemType(roleItem.getItemtype());//itemType:1 装备 2.秘籍 3.道具
////                builder.addBuyItemList(_buyItem.build());
////                builder.setLingShiNum(tRole.getRolelingshinum());  //灵石数量
////            }else {
////                result= 0x2;
////                builder.setResult(result);
////            }
////            player.DirectSend(wrappedBufferShort(buyItemResponse.msgID.ID_VALUE,builder.build()));
////            return;
////        }
////        //3.道具
////        if (itemType== 0x3){
////           PropsModel propsModel= ScriptFactory.itemModelFastMap.get(itemTypeID);
////            int cast=propsModel.getPrice();
////            if (lingShi>=cast){
////                TRoleItemProps itemProps= (TRoleItemProps) roleItemService.recordGoods(roleID, itemTypeID, itemType, ItemOptType.BUY_GOODS.getValue());
////                tRole.setRolelingshinum(lingShi-cast);
////                playerService.updateRole(tRole);
////                modelCacheService.addObjectPrefixID(ModelCacheService.ROLE_PREFIX(roleID), tRole);
////                result= 0x1;
////                //构建购买物品数据信息
////                buyItemVO.Builder _buyItem=buyItemVO.newBuilder();
////                _buyItem.setItemID(itemProps.getPropsid());  //服务器分配的编号（自增长唯一标识）
////                _buyItem.setItemTypeID(itemProps.getPropstypeid());  //物品ID编号 配置文件编号
////                _buyItem.setItemType(itemProps.getItemtype());//itemType:1 装备 2.秘籍 3.道具
////                builder.addBuyItemList(_buyItem.build());
////                builder.setLingShiNum(tRole.getRolelingshinum());
////            }else {
////                result= 0x2;
////                builder.setResult(result);
////            }
////            player.DirectSend(wrappedBufferShort(buyItemResponse.msgID.ID_VALUE,builder.build()));
////        }
//    }
//}
